package ui;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import Work.Jdbc;
/*查询选项四个查询按钮*/
public class BookSearchButtons extends JFrame implements ActionListener {
	private JButton searchall;
	private JButton searchid;
	private JButton searchb_name;
	private JButton searchauthor;
	private JButton returnbutton;
	//创建数据库连接类对象
    Jdbc db = new Jdbc();
	public BookSearchButtons() {
		JFrame jFrame = new JFrame("书籍查询功能选择");
		//JPanel jpc = new JPanel();// 默认流式布局
		jFrame.setLayout(new BorderLayout());
		//jFrame.setSize(300, 200);
		JPanel jp1 = new JPanel(new GridLayout(2, 2, 10, 10));//设置新面板
		// 网格布局GridLayout(int rows, int columns, int hgap, int vgap)行数，列数，组件水平间距，垂直间距
		jp1.setBorder(BorderFactory.createTitledBorder("书籍查询"));
		//this.setLayout(new FlowLayout());
		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

		setTitle("书籍查询系统功能选项");
		setSize(300, 200);
		setLocationRelativeTo(null);
		

		// 监听右上角的退出按钮
		this.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent windowEvent) {
				System.exit(0);
			}
		});
		searchall = new JButton("查询全部书籍");
		searchid = new JButton("按书籍编号查询");
		searchb_name = new JButton("按书籍名称查询");
		searchauthor = new JButton("按作者查询");
		
		jp1.add(searchall);
		jp1.add(searchid);
		jp1.add(searchb_name);
		jp1.add(searchauthor);
		returnbutton = new JButton("返回");
		returnbutton.addActionListener(this);
		returnbutton.setActionCommand("no");
		JPanel jp2 = new JPanel();// 新面板，用于放置按钮
		jp2.add(returnbutton);
		add(jp2, BorderLayout.SOUTH);// 把按钮放到窗口最下方
		getContentPane().add(jp1,BorderLayout.CENTER);
		//add(jpc);
		//add(jpc, BorderLayout.CENTER);
		//jp1.setBounds(200, 50, 150, 40);

		searchall.addActionListener(this);
		searchid.addActionListener(this);
		searchb_name.addActionListener(this);
		searchauthor.addActionListener(this);

		this.setVisible(true);
		
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		BookSearch1 BookSearch1 = new BookSearch1();
		if (e.getSource() == searchall) {
			this.dispose();
			BookSearch1.SearchAllreader(db);
		}else if (e.getSource() == searchb_name) {
			this.dispose();
			BookSearch1.Searchb_namebuttonreader();
		}else if (e.getSource() == searchid) {
			this.dispose();
			BookSearch1.Searchb_idbuttonreader();
		}else if (e.getSource() == searchauthor) {
			this.dispose();
			BookSearch1.Searchb_authorbuttonreader();
		} else if (e.getSource() == returnbutton) {
			this.dispose();
			new ReaderOp();
		}  
	}
}
